import React, { Component } from "react";
import { SafeAreaView, Text, View, StyleSheet, TouchableOpacity, Image, TextInput, PermissionsAndroid, Platform, DeviceEventEmitter, Switch } from 'react-native';
import Constant from '../../utils/Constant'//全局变量
import { getImgUrl } from '../../utils/ComFunction';
import HttpUtils from "../../utils/HttpUtils";
import HttpUrls from "../../utils/HttpUrls";
import Header from "../../components/header";
import { ToastToUser } from "../../utils/CustomToast";
import ActionSheet from 'react-native-actionsheet'
import ImageCropPicker from 'react-native-image-crop-picker';
import Upload from '../../components/upload/Upload'
import { requestCameraPermission, requestWritePermission } from '../../utils/Permission';
import Loading from "../../utils/Loading";
import AndroidModule from "../../utils/AndroidConnent";
import CommonDialog from "../../components/dialog/CommonDialog";
const isAndroid = Platform.OS == 'android';
import DeviceInfo from 'react-native-device-info';

export default class SwitchAPI extends Component {

    constructor(props) {
        super(props);
        this.state = {
            isDev: true,
            isTest: false,
            isRelease: false
        };
    }

    componentDidMount() {
        if(Constant.apiType == 0 || Constant.apiType == 1){
            this.setState({
                isDev: true,
                isTest: false,
                isRelease: false
            })
        }else if(Constant.apiType == 2){
            this.setState({
                isDev: false,
                isTest: true,
                isRelease: false
            })
        }else if(Constant.apiType == 3){
            this.setState({
                isDev: false,
                isTest: false,
                isRelease: true
            })
        }
    }

    render() {
        const navigation = this.props.navigation;
        return (
            <View
                style={styles.container}>
                <Header navigation={navigation} Title={'开发状态地址切换'} />

                <TouchableOpacity
                    style={[styles.itemContain, { marginTop: 30 }]}
                    onPress={() => {
                        this.setState({ isDev: true, isTest: false, isRelease: false });
                    }}>

                    <Image style={styles.checkIcon} source={this.state.isDev ? require('source/image/agent_check.png') : require('source/image/agent_uncheck.png')} />
                    <Text style={styles.titleText}>开发地址</Text>
                </TouchableOpacity>
                <TouchableOpacity
                    style={styles.itemContain}
                    onPress={() => {
                        this.setState({ isDev: false, isTest: true, isRelease: false });
                    }}>

                    <Image style={styles.checkIcon} source={this.state.isTest ? require('source/image/agent_check.png') : require('source/image/agent_uncheck.png')} />
                    <Text style={styles.titleText}>测试地址</Text>
                </TouchableOpacity>
                <TouchableOpacity
                    style={styles.itemContain}
                    onPress={() => {
                        this.setState({ isDev: false, isTest: false, isRelease: true });
                    }}>

                    <Image style={styles.checkIcon} source={this.state.isRelease ? require('source/image/agent_check.png') : require('source/image/agent_uncheck.png')} />
                    <Text style={styles.titleText}>正式地址</Text>
                </TouchableOpacity>


                <TouchableOpacity
                    style={styles.btnConfirm}
                    onPress={() => {
                        let type = 0
                        if(this.state.isDev){
                            type = 1
                        }
                        else if(this.state.isTest){
                            type = 2
                        }else if(this.state.isRelease){
                            type = 3
                        }
                        AndroidModule.switchApi({switchType:type})
                        AndroidModule.logout()
                    }}>
                    <Text style={styles.btnConfirmText}>确定</Text>
                </TouchableOpacity>

            </View>
        );
    }

    

};

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#f9f9f9',
        
    },


    logoImg: {
        width: 80,
        height: 80,
        marginTop: 40
    },
    versionText: {
        fontSize: 14,
        color: '#333333',
        marginTop: 5
    },
    itemContain: {
        flexDirection: 'row',
        alignItems: 'center',

        height: 50,

        width: '100%',
        paddingLeft: 15,
        paddingRight: 15
    },
    titleText: {
        fontSize: 16,
        color: '#333333',
        marginLeft:10
    },
    valueText: {
        fontSize: 16,
        color: '#999999'
    },
    arrow: {
        fontSize: 18,
        color: '#333333',
    },
    arrowImg: {
        width: 15,
        height: 15
    },

    btnConfirm: {
        height: 46,
        marginLeft: 15,
        marginRight: 15,
        backgroundColor: '#ffde00',
        justifyContent: 'center',
        alignItems: 'center',
        borderRadius: 23,
        marginTop:80
    },
    btnConfirmText: {
        color: '#333333',
        fontSize: 14
    }

});